const fs = require('fs');
const axios = require('axios');

async function uploadTest() {
  try {
    // 登录获取token
    const loginResponse = await axios.post('http://localhost:10003/user-service/auth/login', {
      username: 'admin',
      password: '123456'
    });
    
    console.log('Login response:', loginResponse.data);
    
    const token = loginResponse.data.data;
    console.log('Token:', token);
    
    // 上传文件
    const formData = new FormData();
    formData.append('file', fs.createReadStream('test.txt'));
    formData.append('title', 'Test Document');
    formData.append('authors', 'Test Author');
    
    const uploadResponse = await axios.post(
      'http://localhost:10003/document-service/literature/upload',
      formData,
      {
        headers: {
          'Authorization': `Bearer ${token}`,
          ...formData.getHeaders()
        }
      }
    );
    
    console.log('Upload response:', uploadResponse.data);
  } catch (error) {
    console.error('Error:', error.response ? error.response.data : error.message);
  }
}

uploadTest();